<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      #template {
        display: none;
      }
    </style>
  </head>
  <body>
    <!-- <input v-model="value"></input> -->

    <!-- 
      <Comp v-model="compValue" />
      等价于⬇️
      <Comp 
        :model-value="compValue" 
        @update:model-value="compValue = $event"   
        />
     -->
    <div id="template">
      <Comp v-model.trim.number="compValue"></Comp>
    </div>
    <div id="app"></div>
    <script src="../../../../packages/vue/dist/vue.global.js"></script>

    <script>
      const { createApp, ref } = Vue

      const template = document.querySelector('#template')?.innerHTML
      const App = {
        setup() {
          const compValue = ref('')
          const add = () => value.value++
          return {
            compValue,
            add
          }
        },
        template,
        components: {
          Comp: {
            props: ['modelValue'],
            emits: ['update:modelValue'],
            template: `
              <input v-model="value">
            `,
            computed: {
              value: {
                get() {
                  return this.modelValue
                },
                set(value) {
                  this.$emit('update:modelValue', value)
                }
              }
            }
          }
        }
      }

      createApp(App).mount('#app')
    </script>
  </body>
</html>
